﻿using ShareCode.Dto.User.Org.Admin;
using ShareCode.Dto;
using ShareCode.Entity.Corpus;
using ShareCode.KeyValue;

namespace ClientDao.Corpus
{
    public class CorpusVersionDal : BaseTreeDal<CorpusVersionEntity>
    {
        public CorpusVersionDal()
        {
            Controller += "Corpus/CorpusVersion";
        }

        public async Task<ResultDto<bool>> TreeInsertSonWithCover(CorpusVersionEntity entity, string? CoverPath)
        {
            var val = InitDataContent(entity);

            if (!string.IsNullOrEmpty(CoverPath))
                val = InitFileDataContent(val, CoverPath, EnumFileUsage.OrgIcon.ToString());

            var imgstream = await PostFormAsync<bool>($"TreeInsertSonWithCover", val);

            return imgstream;
        }

        public async Task<ResultDto<bool>> UpdateWithCoverAsync(CorpusVersionEntity entity, string? CoverPath)
        {
            var val = InitDataContent(entity);

            if (!string.IsNullOrEmpty(CoverPath))
                val = InitFileDataContent(val, CoverPath, EnumFileUsage.OrgIcon.ToString());

            var imgstream = await PostFormAsync<bool>($"UpdataWithCover", val);

            return imgstream;
        }
    }
}
